package Alee150;

import java.util.Arrays;

/**
 * ClassName: c02
 * Package: Alee150
 * Description:27. 移除元素
 *
 * @Author BCXJ
 * @Create 2025/9/28 08:38
 * @Version 1.0
 * @Since 1.0
 */
public class c02 {

    public static void main(String[] args) {
        int[] arr = {0,1,2,2,3,0,4,2};
        System.out.println(removeElement(arr, 2));
        System.out.println(Arrays.toString(arr));
    }

    public static int removeElement(int[] nums, int val) {
        int res = 0;
        for (int num : nums) {
            if(num != val) {
                nums[res] = num;
                res ++;
            }
        }

        return res;
    }
}
